/**
 * 头像控件
 */
class MJPlayerView extends V.PlayerView {
	public nickNameLabel: eui.Label;//昵称
	public moneyLabel: eui.Label;//钱
	public head: eui.Image;//头像
	public headkuang: eui.Image;//头像框
	public bankerIcon0: eui.Image;//庄家0
	public bankerIcon: eui.Image;//庄家1
	public disconnectImage: eui.Group;//离线
	public ready: eui.Image;//准备
	public tingGroup: eui.Group;//听牌
    public sex: number;//性别

 	/** 游戏结束时手牌 */
    public handCard:number[] = [];
 	/** 结束时牌型 */
    public endType:number;
	/** 结束时牌 */
    public endCards:number[];
    /** 是否已听牌 */
    public isTing:number;
    /** 游戏输赢分 */
    public lGameScore:number;
    

	public constructor() {
		super();
		this.skinName = "HeadSkin";
	}

	public init():void{
        this.start();
    }

    public start(): void {
        this.hidePlayerInfoPanel();
        if (parseInt(this.name.replace("player", "")) == 9) {
            this.visible = AppData.getInstance().userData.status == UserStatus.LOOKON;
        }
    }

    //游戏开始
    public onGameStart(data:any): void {
        //this.moneyLabel.text = base.Utils.formatCurrency(data.lTakeMoney[this.chairId]);
        this.alpha = 1;
        this.tingGroup.visible = false;
        this.ready.visible = false;
        this.disconnectImage.visible = false;
        if(this.chairId == data.wDUser) this.setwDUserUI();
        else this.bankerIcon.visible = false;
        if(this.isMe()){
            this.handCard = data.cbCardData[this.chairId];
        } else this.handCard = [];
    }

    /** 同步桌子 */
    public onSyncData(data:any):void{
        if(!this.visible) return;
        this.moneyLabel.text = base.Utils.formatCurrency(data.lTakeMoney[this.chairId] - data.lTotalScore[this.chairId]);
        if(this.chairId == data.wDUser) this.setwDUserUI();
        else this.bankerIcon.visible = false;
        if(this.isMe()){
            this.handCard = data.cbHandCardData;
        }else{
            this.handCard = [];
        }
    }
   
    /**设置庄家UI*/
    public setwDUserUI(): void {
        this.bankerIcon.visible = true;
    }

	/**设置听牌*/
    public setTingUI(): void {
        this.tingGroup.visible = true;
    }
     
    public show():boolean{
        super.show()
        this.setSitUI(D.App.table.players[this.chairId]);
        return true;
    }

	//玩家状态
    public status():void{
        if(this.getData().userStatus == UserStatus.OFFLINE){
            this.disconnectImage.visible = true;
        }
		else if(this.getData().userStatus == UserStatus.READY){
			this.ready.visible = true;
		}
    }

    //设置坐下UI（玩家进入坐下的状态）
    public setSitUI(data: D.PlayerData): void {
        console.log("setSitUI", data);
        if (data) {
            this.sex = data.gender;
            this.showPlayerInfoPanel();
            this.nickNameLabel.text = this.isMe() ? base.Utils.formatNickName(data.nickName, 10) : data.nickName;
            this.head.source = data.gender == 1 ? "mj_man" + data.faceID + "_png" : "mj_women" + data.faceID + "_png";
            this.moneyLabel.text = base.Utils.formatCurrency(data.score);
            this.bankerIcon.visible = false;
            this.bankerIcon0.visible = false;
            this.disconnectImage.visible = data.userStatus == UserStatus.OFFLINE;
            this.ready.visible = false;
            this.tingGroup.visible = false;
            if(data.userStatus == UserStatus.PLAY){
                if(this.isMe()){
					
                }else {

				};
            }
        }
    }
    //设置离开UI（包括起立、旁观、离开）
    public setLeaveUI(): void {
        this.hidePlayerInfoPanel();
    }
    //隐藏用户信息
    public hidePlayerInfoPanel(): void {
        this.visible = false;
        this.bankerIcon.visible = false;
        this.bankerIcon0.visible = false;
        this.disconnectImage.visible = false;
        this.ready.visible = false;
        this.tingGroup.visible = false;
    }
    //显示用户信息
    public showPlayerInfoPanel(): void {
        this.bankerIcon.visible = true;
        this.bankerIcon0.visible = true;
        this.disconnectImage.visible = true;
        this.ready.visible = true;
        this.tingGroup.visible = true;
    }

    //设置玩家身上的金币数
    public showPlayerMoney(money): void 
    {
        this.moneyLabel.text = base.Utils.formatCurrency(money);
    }

    //收到游戏结束
    public onGameEnd(data: any): void 
    {
        this.lGameScore = data;
        this.getData().gameScore += this.lGameScore;
        this.showPlayerMoney(this.getData().gameScore);
    }

}